#ifndef C2048_H
#define C2048_H

#include <QObject>
#include <QTime>
#include <QDebug>
#include <QColor>

#include <vector>
#include <algorithm>

class C2048 : public QObject {
    Q_OBJECT
    Q_ENUMS(Move_Direction)
    Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged)
    Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged)
    Q_PROPERTY(int score READ score)
    Q_PROPERTY(int bestScore READ bestScore)

  public:
    C2048(QObject *parent = 0);
    ~C2048();

    enum Move_Direction {
        Move_Up = 0,
        Move_Down,
        Move_Left,
        Move_Right
    };

    Q_INVOKABLE void init();
    Q_INVOKABLE void moveKey(Move_Direction direc);
    Q_INVOKABLE QColor color(const int, const int);

    int rows() const;
    void setRows(const int);
    int columns() const;
    void setColumns(const int);
    int score() const;
    int bestScore() const;

  signals:
    void rowsChanged();
    void columnsChanged();

  public slots:
    //void goBack();
    int show(const int i, const int j);

  private:
    //int m_step;
    int m_rows;
    int m_columns;
    int m_score;
    int m_bestScore;

    /*
        typedef std::vector<int> NumPanel;
        typedef std::vector<int> NumState;
        NumPanel m_number;
        Numpanel m_index;
        NumState m_state;
    */

    std::vector<std::vector<int> > m_number;

    void createNewTile(bool isStartup);
    void mergeVector(std::vector<int> &v0);
};

#endif // C2048_H
